﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using miniCCR;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace SimpleGameAppCCR.NComp
{



    public class SpriteCM_Proxy : miniCCR.Proxy
    {
        public SpriteCM_Proxy(GComponent from, GComponent to) : base(from,to)
            
        {

        }
    }


    public class SpriteCM : miniCCR.GComponent
    {


        public override string GetProxyName()
        {
            return typeof(SpriteCM_Proxy).Name;
        }

        public override miniCCR.Proxy GetProxy(GComponent from)
        {
            SpriteCM_Proxy proxy = new SpriteCM_Proxy(this,from);


            return proxy;
        }




        public override uint _ComID
        {
            get { return (uint)COMID.SPRITECM; }
        }
    

        Random _Rand = new Random();



        public override IEnumerator<miniCCR.iTask> OnMessage(miniCCR.Operation op)
        {
            if (op.ToString() == typeof(Operation.LoadContent).ToString())
            {
                return LoadContent(op as Operation.Draw);
            }

            return null;
        }

        private IEnumerator<iTask> LoadContent(SimpleGameAppCCR.Operation.Draw draw)
        {

            GObject obj;

            for (int i = 0; i < 2; i++)
            {

                obj = new GObject();
                NComp.Sprite sprite = new NComp.Sprite(Game1.I.Content.Load<Texture2D>("SquareGuy"));
                sprite._mPosition.X = _Rand.Next(600);
                sprite._mPosition.Y = _Rand.Next(400);

                obj.AddComponent(sprite);

                obj.AddComponent(new NComp.Movable());


                miniCCR.ccrMain.I.AddGObject(obj);
            }

            yield break;
        }


        public override IEnumerator<miniCCR.iTask> InitHandle(miniCCR.Init op)
        {



            yield break;


            //for (int i = 0; i < 1000; i++)
            //{
            //    obj = new miniCCR.GObject();
            //    NComp.Sprite sprite = new NComp.Sprite(this.Content.Load<Texture2D>("SquareGuy2"));
            //    sprite._mPosition.X = _Rand.Next(8000);
            //    sprite._mPosition.Y = _Rand.Next(8000);

            //    obj.SetComponent(sprite);

            //    _ccrMain.AddObject(obj);

            //}
        }


    }
}
